/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ADT;
import static ADT.Values.*;
/**
 *
 * @author Martin
 */
public class LengthInM extends Scalar implements Length 
{
    private final double meters;
    @Override public boolean isValid(){return true;}
    @Override public boolean isZero(){return meters == 0;}
    //Objekterstellung
    private LengthInM(double meters){
        this.meters = meters;
    }
        //Accessors für alle verschiedenen Variationen der Größe
        double getValue() {
                return meters;
        }
        
        @Override
        public double getFt() {
                return meters / FEET_IN_METERS;
        }

        @Override
        public double getM() {
                return meters;
        }
        
        @Override
        public double getKm() {
                return meters / KILO;
        }
        //Inverser Wert
        @Override
        public Length inverse() {
                return new LengthInM(this.getM() * -1);
        }
        
        //Arithmetische Operatoren
        @Override
        public Length add(Length length) {
                return valueOf(this.getM() + length.getM());
        }
        @Override
        public Length sub(Length length) {
                return valueOf(this.getM() - length.getM());
        }

        
        // STANDARD HETEROGENOUS ARITHMETIC
        @Override
        public Length mul(double factor) {
                return valueOf(this.getM() * factor);
        }

        @Override
        public Length div(double factor) {
                return valueOf(this.getM() / factor);
        }

        @Override
        public double div(Length length) {
                return (this.getM() / length.getM());
        }
        
        //Vergleichbarkeit
        @Override
        public int compareTo(Length length) {
                return Double.compare(this.getM(), length.getM());
        }

        @Override
        public boolean equals(Object o) {
                if (o == this)
                        return true;
                if (!(o instanceof LengthInM))
                        return false;
                return this.compareTo((LengthInM) o) == 0;
        }

        @Override
        public String toString() {
                return String.format("%.2d m", this.getM());
        }

        public static LengthInM valueOf(double meters) {
                return new LengthInM(meters);
        }
        
        @Override
        public int hashCode(){
                return hashDouble(meters);
        }
}
